<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:p="http://primefaces.org/ui"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core">
<h:head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
	<title>Insert title here</title>
</h:head>
<h:body >
	<h:form id="userForm">

		<p:commandButton id="addUserButton" value="New User"
			action="#{userView.prepareNewUser()}" oncomplete="userDialog.show()">
		</p:commandButton>
		<p:dataTable value="#{userView.users}" var="user">
			<p:column>
				<f:facet name="header">Name</f:facet>
				<h:outputText value="#{user.name}" />
			</p:column>
			<p:column>
				<f:facet name="header">Address</f:facet>
				<h:outputText value="#{user.address}" />
			</p:column>
			<p:column>
				<p:commandButton id="editButton" title="Edit" value="Edit"
					update=":userForm:dlgContent" oncomplete="userDialog.show()">
					<f:setPropertyActionListener value="#{user}"
						target="#{userView.selectedUser}" />
				</p:commandButton>
			</p:column>
		</p:dataTable>
		<p:dialog id="userDialog" widgetVar="userDialog">
			<h:panelGrid id="dlgContent" columns="2">
				<h:outputLabel value="Id"></h:outputLabel>
				<h:inputText value="#{userView.selectedUser.id}"></h:inputText>
				<h:outputLabel value="Name"></h:outputLabel>
				<h:inputText value="#{userView.selectedUser.name}"></h:inputText>
				<h:outputLabel value="Address"></h:outputLabel>
				<h:inputText value="#{userView.selectedUser.address}"></h:inputText>
				<p:commandButton value="Cancel" oncomplete="userDialog.hide()"></p:commandButton>
				<p:commandButton value="Save User" action="#{userView.saveUser()}"
					oncomplete="userDialog.hide()" update="@parent"></p:commandButton>
			</h:panelGrid>
		</p:dialog>
	</h:form>
</h:body>
</html>